package com.yhao.stock.common.stock;

import cn.hutool.db.Db;
import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity;
import com.yhao.stock.common.utils.CSVUtil;
import com.yhao.stock.common.utils.JdbcUtil;
import com.yhao.stock.entity.DayInfo;
import lombok.extern.slf4j.Slf4j;

import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : yhao
 * @Date : 2023/12/5 - 7:36
 * @Desc : 日表信息分析
 */
@Slf4j
public class DayInfoAna {

    /**
     * @param startDate
     * @param endDate
     * @desc 获取指定日期查的股票差值
     */
    public static void getRangeRF(String startDate, String endDate) {
        List<DayInfo> stockList = StockBaseUtil.getStock();
        List<String> resultList = new ArrayList<>();
        String content = "";
        for (DayInfo dayInfo : stockList) {
            final String code = dayInfo.getdCode();
            final String name = dayInfo.getdName();
            Double finalPrice = StockBaseUtil.getPriceByDate(code, endDate);
            Double startPrice = StockBaseUtil.getPriceByDate(code, startDate);
            if (finalPrice == -1) {
                log.info("finalPrice  为null" + code);
                continue;
            }
            if (startPrice == -1) {
                log.info("startPrice  为null" + code);
                continue;
            }

            content = code + "," + name + "," + (finalPrice - startPrice) + "," + finalPrice + "," + startPrice;
            resultList.add(content);
        }
        CSVUtil.exportCsv("D:\\dayDiff.csv", resultList);
        log.info("getRangeRF  执行完成" + LocalDateTime.now());
    }


    public static void main(String[] args) {
        getRangeRF("2023-11-14", "2023-12-04");
        // final Double priceByDate = getPriceByDate("000001", "2023-12-04");
        // System.out.println("priceByDate----------" + priceByDate);
    }
}
